package com.situ.ssh.action;

import com.opensymphony.xwork2.ActionSupport;
import com.situ.ssh.entity.User;
import com.situ.ssh.service.IUserService;
import com.situ.ssh.util.JSONUtil;
import com.situ.ssh.util.Result;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class UserAction extends ActionSupport {
    @Autowired
    IUserService userService;

    public String selectAll() {
        System.out.println("UserAction.selectAll");
        List<User> list = userService.selectAll();
        HttpServletRequest request = ServletActionContext.getRequest();
        request.setAttribute("list", list);
        return "list";
    }

    public void selectAllJson() {
        System.out.println("UserAction.selectAllJson");
        List<User> list = userService.selectAll();
        // JSONUtil.array2Json(list);
        Result result = Result.success("", list);
        JSONUtil.obj2Json(result);
    }
}
